import React from 'react';
import { Router, Route, Switch,Redirect } from 'dva/router';
import Loadable from 'react-loadable'


const Routes = [
    {path: '/', component: Loadable({loader: () => import('./routes/default'), loading: () =>(<div></div>)}), exact: true},
    {path: '/index', component: Loadable({loader: () => import('./routes/serviceUpgrade'), loading: () =>(<div></div>)}),auth:false},
    // {path: '/index', component: Loadable({loader: () => import('./routes/default'), loading: () =>(<div></div>)})},
    // {path: '/home', component: Loadable({loader: () => import('./routes/home'), loading: () =>(<div></div>)}), exact: true,auth:false},
    // {path: '/ph', component: Loadable({loader: () => import('./routes/ph'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/ph/phDate', component: Loadable({loader: () => import('./routes/phDates'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/ph/phDate/phTime', component: Loadable({loader: () => import('./routes/phTime'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/ph/push', component: Loadable({loader: () => import('./routes/phPush'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/paihao', component: Loadable({loader: () => import('./routes/manage/paihao'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/my', component: Loadable({loader: () => import('./routes/my'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/setting', component: Loadable({loader: () => import('./routes/manage/setting'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/window', component: Loadable({loader: () => import('./routes/manage/setting/window'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/window/edit', component: Loadable({loader: () => import('./routes/manage/setting/window/edit'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/busiType', component: Loadable({loader: () => import('./routes/manage/setting/busiType'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/busiType/new', component: Loadable({loader: () => import('./routes/manage/setting/busiType/new'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/sms', component: Loadable({loader: () => import('./routes/manage/setting/sms'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/holiday', component: Loadable({loader: () => import('./routes/manage/setting/holiday'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/businesstime', component: Loadable({loader: () => import('./routes/manage/setting/businessTimeMgr'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/business', component: Loadable({loader: () => import('./routes/business'), loading: () =>(<div></div>)}), exact: true,auth:true},// PC断业务员操作排号页面
    // {path: '/view_queue', component: Loadable({loader: () => import('./routes/view_queue'), loading: () =>(<div></div>)}), exact: true,auth:true},
    {path: '/bt_reserve', component: Loadable({loader: () => import('./routes/businessTypeReserve'), loading: () =>(<div></div>)}), exact: true,auth:true},
    {path: '/manage/sysBusiType', component: Loadable({loader: () => import('./routes/manage/setting/sysbusitype'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/addSysBusiType', component: Loadable({loader: () => import('./routes/manage/setting/sysbusitype/sysbusitypeedit/add'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/updateSysBusiType', component: Loadable({loader: () => import('./routes/manage/setting/sysbusitype/sysbusitypeedit/edit'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/busiType/binding', component: Loadable({loader: () => import('./routes/manage/setting/sysbusitype/sysbusitypeedit/binding'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/cms/edit', component: Loadable({loader: () => import('./routes/manage/cms/edit'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/cms/detail', component: Loadable({loader: () => import('./routes/manage/cms/detail'), loading: () =>(<div></div>)}), exact: true,auth:false},
    {path: '/manage/cms/list', component: Loadable({loader: () => import('./routes/manage/cms/list'), loading: () =>(<div></div>)}), exact: true,auth:false},

]

const login=Routes.filter(item=>item.path==='/manage/paihao')

//http://www.bubuko.com/infodetail-2685181.html
function RouterConfig({ history }) {
  return (
    <Router history={history}>
      <Switch>
      {Routes.map((route, idx) => {
        if(route.path==='/'){
          return <Redirect key={idx} {...route}  to="/index/ph"/>
        }
        return <Route key={idx} {...route} />
        // let adopt=true;//是否允许路由通过，默认允许
        // const account=localStorage.getItem('account')
        // if (route.auth && !account){
        //   adopt=false
        // }
        // return (
        //     // <Route key={idx} {...route} render={props=>} />
        //     <Route key={idx} path={route.path} exact render={props =>
        //                        (adopt ? (<route.component {...props} />) : <Redirect to={{
        //                         pathname: '/manage/paihao',
        //                         state: { from: props.location }
        //                       }} />
        //                        )} />
        // )
      })}
      </Switch>
    </Router>
  );
}

export default RouterConfig;
